package com.niuxiaofa.newlaw.Network;

import android.widget.Toast;

import com.google.gson.Gson;
import com.niuxiaofa.newlaw.Bean.AdvisoryTagBean;
import com.niuxiaofa.newlaw.Bean.BaseBean;
import com.niuxiaofa.newlaw.Bean.DemandTagsBean;
import com.niuxiaofa.newlaw.Bean.ExpertBean;
import com.niuxiaofa.newlaw.Bean.LocalCitiesBean;
import com.niuxiaofa.newlaw.Bean.LocalProvincesBean;
import com.niuxiaofa.newlaw.Bean.NewListBean;
import com.niuxiaofa.newlaw.Bean.NewListBean;
import com.niuxiaofa.newlaw.Bean.QuestionBankBean;
import com.niuxiaofa.newlaw.Bean.SignPageBean;
import com.niuxiaofa.newlaw.Bean.TimeofAssessmentBean;
import com.niuxiaofa.newlaw.Tools.UIUtils;

import java.util.Map;

import okhttp3.MediaType;
import okhttp3.RequestBody;
import retrofit2.Call;
import retrofit2.Callback;
import retrofit2.Response;

public class WisdomLibraryPresenter {



    public static void newList(interface_newList interface_newList) {

        Call<NewListBean> call = ServiceManager.getInstance().creat(ApiService.class).newList(1,3);

        call.enqueue(new Callback<NewListBean>() {
            @Override
            public void onResponse(Call<NewListBean> call, Response<NewListBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    NewListBean baseBean = (NewListBean) response.body();
                    interface_newList.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<NewListBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_newList {
        void getResponse(NewListBean u);
    }


    public static void advisoryTag(String advisoryTag,interface_advisoryTag interface_advisoryTag) {

        Call<AdvisoryTagBean> call = ServiceManager.getInstance().creat(ApiService.class).advisoryTag(advisoryTag);

        call.enqueue(new Callback<AdvisoryTagBean>() {
            @Override
            public void onResponse(Call<AdvisoryTagBean> call, Response<AdvisoryTagBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    AdvisoryTagBean baseBean = (AdvisoryTagBean) response.body();
                    interface_advisoryTag.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<AdvisoryTagBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_advisoryTag{
        void getResponse(AdvisoryTagBean u);
    }


    public static void demandTags(interface_demandTags interface_demandTags) {

        Call<DemandTagsBean> call = ServiceManager.getInstance().creat(ApiService.class).advisoryTag();

        call.enqueue(new Callback<DemandTagsBean>() {
            @Override
            public void onResponse(Call<DemandTagsBean> call, Response<DemandTagsBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    DemandTagsBean baseBean = (DemandTagsBean) response.body();
                    interface_demandTags.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<DemandTagsBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_demandTags{
        void getResponse(DemandTagsBean u);
    }



    public static void getLocalProvinces(interface_getLocalProvinces interface_getLocalProvinces) {

        Call<LocalProvincesBean> call = ServiceManager.getInstance().creat(ApiService.class).getLocalProvinces();

        call.enqueue(new Callback<LocalProvincesBean>() {
            @Override
            public void onResponse(Call<LocalProvincesBean> call, Response<LocalProvincesBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    LocalProvincesBean baseBean = (LocalProvincesBean) response.body();
                    interface_getLocalProvinces.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<LocalProvincesBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_getLocalProvinces{
        void getResponse(LocalProvincesBean u);
    }



    public static void getLocalCities(Map map, interface_getLocalCities interface_getLocalCities) {

        Gson gson = new Gson();

        String json=gson.toJson(map);

        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),json);
        Call<LocalCitiesBean> call = ServiceManager.getInstance().creat(ApiService.class).getLocalCities(body);

        call.enqueue(new Callback<LocalCitiesBean>() {
            @Override
            public void onResponse(Call<LocalCitiesBean> call, Response<LocalCitiesBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    LocalCitiesBean baseBean = (LocalCitiesBean) response.body();
                    interface_getLocalCities.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<LocalCitiesBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_getLocalCities{
        void getResponse(LocalCitiesBean u);
    }



    public static void getExpert(Map map, interface_getExpert interface_getExpert) {
        Gson gson = new Gson();

        String json=gson.toJson(map);

        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),json);
        Call<ExpertBean> call = ServiceManager.getInstance().creat(ApiService.class).getExpert(body);

        call.enqueue(new Callback<ExpertBean>() {
            @Override
            public void onResponse(Call<ExpertBean> call, Response<ExpertBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    ExpertBean baseBean = (ExpertBean) response.body();
                    interface_getExpert.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<ExpertBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_getExpert{
        void getResponse(ExpertBean u);
    }


    public static void getSignPage(Map map, interface_getSignPage interface_getSignPage) {
        Gson gson = new Gson();

        String json=gson.toJson(map);

        RequestBody body = RequestBody.create(MediaType.parse("application/json; charset=utf-8"),json);
        Call<SignPageBean> call = ServiceManager.getInstance().creat(ApiService.class).getSignPage(body);

        call.enqueue(new Callback<SignPageBean>() {
            @Override
            public void onResponse(Call<SignPageBean> call, Response<SignPageBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    SignPageBean baseBean = (SignPageBean) response.body();
                    interface_getSignPage.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<SignPageBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_getSignPage{
        void getResponse(SignPageBean u);
    }



    public static void getSignNum( interface_getSignNum interface_getSignNum) {


        Call<BaseBean> call = ServiceManager.getInstance().creat(ApiService.class).getSignNum();

        call.enqueue(new Callback<BaseBean>() {
            @Override
            public void onResponse(Call<BaseBean> call, Response<BaseBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    BaseBean baseBean = (BaseBean) response.body();
                    interface_getSignNum.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<BaseBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_getSignNum{
        void getResponse(BaseBean u);
    }



    public static void setSignDate(interface_setSignDate interface_setSignDate) {

        Call<BaseBean> call = ServiceManager.getInstance().creat(ApiService.class).setSignDate();

        call.enqueue(new Callback<BaseBean>() {
            @Override
            public void onResponse(Call<BaseBean> call, Response<BaseBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    BaseBean baseBean = (BaseBean) response.body();
                    interface_setSignDate.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<BaseBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_setSignDate{
        void getResponse(BaseBean u);
    }


    public static void getTimeofAssessment(interface_getTimeofAssessment interface_getTimeofAssessment) {

        Call<TimeofAssessmentBean> call = ServiceManager.getInstance().creat(ApiService.class).getTimeofAssessment();

        call.enqueue(new Callback<TimeofAssessmentBean>() {
            @Override
            public void onResponse(Call<TimeofAssessmentBean> call, Response<TimeofAssessmentBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    TimeofAssessmentBean baseBean = (TimeofAssessmentBean) response.body();
                    interface_getTimeofAssessment.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<TimeofAssessmentBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_getTimeofAssessment{
        void getResponse(TimeofAssessmentBean u);
    }



    public static void getQuestionBank(interface_getQuestionBank interface_getQuestionBank) {

        Call<QuestionBankBean> call = ServiceManager.getInstance().creat(ApiService.class).getQuestionBank();

        call.enqueue(new Callback<QuestionBankBean>() {
            @Override
            public void onResponse(Call<QuestionBankBean> call, Response<QuestionBankBean> response) {
                //判断请求是否成功
                if (response.isSuccessful()) {
                    QuestionBankBean baseBean = (QuestionBankBean) response.body();
                    interface_getQuestionBank.getResponse(baseBean);
                }
            }

            @Override
            public void onFailure(Call<QuestionBankBean> call, Throwable t) {
//            Log.e("链接错误", t.getMessage());
                Toast.makeText(UIUtils.getActivity(),"网络连接异常,请稍候在试",Toast.LENGTH_LONG).show();
            }
        });

    }
    public interface interface_getQuestionBank{
        void getResponse(QuestionBankBean u);
    }



}
